package tests.common.ui;

import java.util.ArrayList;

import harima.agameditor.common.control.AwesomeEditorEnviroment;
import harima.agameditor.common.ui.BaseEditorPanel;
import harima.agameditor.common.ui.BaseEditorView;

import javax.swing.JPanel;

import tests.common.mocks.MockEditorPanel;
import tests.common.mocks.MockEditorView;
import junit.framework.TestCase;

public class BaseEditorViewFixture extends TestCase{

	
	BaseEditorView view = new MockEditorView();
	AwesomeEditorEnviroment envyroment = new AwesomeEditorEnviroment();
	
	public void test_CanRegisterPanel_RegisterPanelRequested_Always() throws Exception {
		MockEditorPanel panel = new MockEditorPanel();
		((MockEditorView)view).addPanelToBaseClass(panel);
		assertNotNull(view.getPanel(panel.getPanelId()));
		assertSame(panel, view.getPanel(panel.getPanelId()));
	}
	
	public void test_CanStoreViewController_Always() throws Exception {
		Object obj = new Object();
		view.setController(obj);
		assertNotNull(view.getController());
		assertSame(obj, view.getController());
	}
	
	public void test_SetsControllerToChildPanels_Always() throws Exception {
		view = new MockEditorView();
		Object controller = new Object();
		view.setController(controller);
		ArrayList<MockEditorPanel> panels = new ArrayList<MockEditorPanel>();
		int panelCount = 10;
		for(int i=0; i<panelCount; i++)
		{
			MockEditorPanel panel = new MockEditorPanel("" + i);
			panels.add(panel);
		    ((MockEditorView)view).addPanelToBaseClass(panel);
		}
		
		view.addControllerToChildPanels();
		
		for(int i=0; i<panelCount; i++)
		{
			BaseEditorPanel<Object> panel = view.getPanel(""+i);
			assertNotNull(panel.getController());
			assertSame(controller, panel.getController());
		}
	}

}


